
pkgbase="sqlite"
pkgname=('sqlite' 'sqlite-tcl' 'sqlite-doc') 
_amalgamationver=3240000
_docver=3240000
pkgver=3.24.0
pkgrel=1
pkgdesc="A C library that implements an SQL database engine"
arch=('x86_64')
license=('custom')
url="http://www.sqlite.org/"
makedepends=('tcl' 'readline>=6.0.00')
source=("http://www.sqlite.org/2018/sqlite-autoconf-${_amalgamationver}.tar.gz"
        "http://www.sqlite.org/2018/sqlite-doc-${_docver}.zip"
        'license.txt')
options=('!libtool' '!emptydirs' '!makeflags')
sha1sums=('da68915e3563b5244cbcdb6c7e20fb35559bcfc6'
          '9684d06b7e6ec1868b1ef075993dc29d952dac97'
          'f34f6daa4ab3073d74e774aad21d66878cf26853')

build() {
  export CFLAGS="$CFLAGS -DSQLITE_ENABLE_COLUMN_METADATA=1 \
                         -DSQLITE_ENABLE_UNLOCK_NOTIFY \
                         -DSQLITE_SECURE_DELETE \
                         -DSQLITE_ENABLE_DBSTAT_VTAB=1"

  # sqlite
  cd ${srcdir}/sqlite-autoconf-${_amalgamationver}
  ./configure --prefix=/usr \
	--disable-static \
	--enable-fts5 \
	--enable-json1 
  make
  
  # tcl extension    
  cd ${srcdir}/sqlite-autoconf-${_amalgamationver}/tea
  ./configure --prefix=/usr \
	--with-system-sqlite
  make

}

package_sqlite() {
 
 pkgdesc="A C library that implements an SQL database engine"
 depends=('readline>=6.0.00')
 provides=("sqlite3=$pkgver")
 replaces=('sqlite3')
 
  cd ${srcdir}/sqlite-autoconf-${_amalgamationver}
  make DESTDIR=${pkgdir} install
  
  install -D -m644 ${srcdir}/license.txt ${pkgdir}/usr/share/licenses/${pkgname}/license.txt
}

package_sqlite-tcl() {
 
 pkgdesc="sqlite Tcl Extension Architecture (TEA)"
 depends=('sqlite')
 provides=("sqlite3-tcl=$pkgver")
 replaces=("sqlite3-tcl")

  cd ${srcdir}/sqlite-autoconf-${_amalgamationver}/tea
  make DESTDIR=${pkgdir} install
}

package_sqlite-doc() {
 pkgdesc="most of the static HTML files that comprise this website, including all of the SQL Syntax and the C/C++ interface specs and other miscellaneous documentation"
 provides=("sqlite3-doc=$pkgver")
 replaces=("sqlite3-doc")
 
  cd ${srcdir}/sqlite-doc-${_docver}
  mkdir -p ${pkgdir}/usr/share/doc/${pkgbase}
  cp -R *  ${pkgdir}/usr/share/doc/${pkgbase}/
  
  # fix permissions and remove obsolete files
  find ${pkgdir} -type f -perm 755 -exec ls -lha {} \;
  find ${pkgdir} -type f -perm 755 -exec chmod 644 {} \;

  find ${pkgdir} -type f -name '*~' -exec ls -lha {} \;
  find ${pkgdir} -type d -name '*~' -exec ls -lha {} \;
  find ${pkgdir} -name '*~' -exec rm -f {} \;

  find ${pkgdir} -type f -name '.~*' -exec ls -lha {} \; # /build/pkg/sqlite-doc/usr/share/doc/sqlite3/images/fileformat/.~lock.indexpage.odg#
  find ${pkgdir} -type d -name '.~*' -exec ls -lha {} \;
  find ${pkgdir} -name '.~*' -exec rm -f {} \;
}

